
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.common.by import By


chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

# path是自己电脑的Chrome浏览器文件地址
path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
chrome_options.binary_location = path

browser = webdriver.Chrome(options=chrome_options)


# service = Service('C:\pydd\pythonProject\chromedriver.exe')

# browser = webdriver.Chrome(service=service, options=chrome_options)


url = 'https://www.baidu.com'

browser.get(url)


# 元素定位

# # 根据id找到对象    常用
# button = browser.find_element(By.ID, 'su')
# print(browser.title, 1, button)

# 根据标签属性的属性值来获取对象
# button = browser.find_element(By.NAME, 'wd')
# print(button)

# 根据xpath语句来获取对象    常用
# button = browser.find_elements(By.XPATH, '//input[@id="su"]')
# print(button)

# 根据标签的名字来获取对象
# button = browser.find_elements(By.TAG_NAME, 'input')
# print(button)

# 使用的bs4 的语法来获取对象   常用
# button = browser.find_elements(By.CSS_SELECTOR, '#su')
# print(button)

button = browser.find_elements(By.LINK_TEXT, '视频')
print(button)

